package com.hn.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hn.dao.StudentDao;
import com.hn.pojo.Student;
import com.hn.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @作者 : wangchangdian
 * @创建时间 : 2019/3/26 - 22:16
 */
@Service("studentService")
public class StudentServiceImpl implements StudentService {

    @Resource
    StudentDao studentDao;
    @Override
    public void addStu(Student student) {
        studentDao.addStu(student);
    }

    @Override
    public Student findStu(int ID) {
        return studentDao.findStu(ID);
    }

    @Override
    public List<Student> findAllStu() {
         return studentDao.findAllStu();
    }

    //分页查询所有学生
    @Override
    public PageInfo<Student> findAllStuPage(int currentPage, int pageSize) {
       String orderBy = "CreateDate desc"; //根据时间降序
        //装载分页信息
        PageHelper.startPage(currentPage, pageSize,orderBy);
        //查询到的结果集
        List<Student> stus = studentDao.findAllStu();
        //获取结果集的分页信息
        PageInfo<Student> pageInfo = new PageInfo<>(stus);

        //返回结果集
        return pageInfo;

    }

    //修改学生信息
    public void editStu(Student StuName){
        studentDao.editStu(StuName);
    }

    @Override
    public void deleteStu(int ID) {
        studentDao.deleteStu(ID);
    }

//    模糊分页查询
    @Override
    public PageInfo<Student> findLikeStu(String content, int currentPage, int pageSize) {

        String orderBy = "CreateDate desc"; //根据时间降序
        //装载分页信息
        PageHelper.startPage(currentPage, pageSize,orderBy);
        //查询到的结果集
        List<Student> stus = studentDao.findLikeStu(content);
        //获取结果集的分页信息
        PageInfo<Student> pageInfo = new PageInfo<>(stus);

        //返回结果集
        return pageInfo;


    }

}
